/*
 * @Author: huangtianyang 916072572@qq.com
 * @Date: 2023-08-15 16:28:37
 * @LastEditors: huangtianyang
 * @LastEditTime: 2023-10-26 12:36:12
 * @FilePath: \cxl-admin\src\pages\consumeManage\topUp\statistics\index.ts
 */
import { BaseData, BaseMethod } from '@/utils/basc-data'
import * as tableConfig from './config.json'
import { reactive, ref } from 'vue'
import { topUpParams, topUpStatisticsList } from '@/apis/consume/topUp'
import { CreateXMLHttpRequest } from '@/utils'

export default class ConsumeTopUpStatisticsData extends BaseData implements BaseMethod {
    companyId = ''
    dialog = reactive({
        title: '',
        visible: false,
        companyId: ''
    })
    constructor() {
        super(tableConfig)
        this.getData()
    }

    getData = (arg?: any) => {
        const obj: topUpParams = {
            current: this.pageData.pagination.pageNo,
            size: this.pageData.pagination.pageSize
        }
        if (this.companyId) {
            obj.companyId = this.companyId
        }
        topUpStatisticsList(obj).then(res => {
            if (res.data.value === 200) {
                this.pageData.pagination.total = res.data.data.total
                this.pageData.table.data.length = 0

                res.data.data.records.forEach((item: any) => {
                    this.pageData.table.data.push(item)
                })
            }
        })
    }
    onSearch = (arg?: any) => {
        this.companyId = arg.companyId
        this.getData()
    }
    onReset = (arg?: any) => {
        this.pageData.pagination.pageNo = 1
        this.companyId = ''
        this.getData()
    }
    onPaginationChange = (arg?: any) => {
        this.pageData.pagination.pageNo = arg
        this.getData()
    }
    onPaginationSize = (arg?: any) => {
        this.pageData.pagination.pageNo = 1
        this.pageData.pagination.pageSize = arg
        this.getData()
    }
    onOperation = (arg?: any) => {
        const { type, data } = arg
        console.log(type, data, arg)
        if (type === 'look') {
            this.dialog.visible = true
            this.dialog.title = data.companyName
            this.dialog.companyId = data.companyId
        } else if (type === 'export') {
            let params = ''
            if (this.uStore.isSuperAdmin || Number(this.uStore.companyId) === 1) {
                params = `current=99&size=99&companyId=${this.companyId}`
            } else {
                params = `current=99&size=99&companyId=${this.uStore.companyId}`
            }
            console.log('params', params)
            const url =
                import.meta.env.VITE_HOST + '/api/mall/company/store/store-statistics-page-list/export?' + params

            CreateXMLHttpRequest(url, '充值汇总列表')
        }
    }
    onDialogVisible = () => {
        this.dialog.visible = false
    }
}
